package com.elong.android.specialhouse.dialogutil;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.elong.android.specialhouse.R;
import com.elong.framework.netmid.ElongRequest;

/**
 * Http事件基本Dialog，持有任务操作回调对象，以及绑定Task。 显示对话框之前需要绑定Task!
 * 
 * @author Peng.Liu
 * 
 */
public abstract class BaseHttpDialog extends Dialog {
	protected int parentViewId;
	protected View mainView;

	protected BaseHttpDialog(Context context) {
		super(context);

		init(context);
	}

	protected void init(Context context) {
		setParentView();

		requestWindowFeature(Window.FEATURE_NO_TITLE);

		Window window = getWindow();
		window.setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(android.R.color.transparent)));
		LayoutInflater inflater = LayoutInflater.from(context);
		mainView = inflater.inflate(parentViewId, null);
		setContentView(mainView);
		setCancelable(false);
	}

	// 设置主Layout 获得parentViewId
	abstract public void setParentView();

	// 绑定任务
	protected ElongRequest request;

	// 绑定任务
	public void bindRequest(ElongRequest request) {
		this.request = request;
	}

	// 设置显示消息内容
	public void setMessage(String message) {
		mainView.findViewById(R.id.dialog_message).setVisibility(View.VISIBLE);
		TextView msgView = (TextView) mainView.findViewById(R.id.dialog_message);
		msgView.setText(message);
	}

	// 设置标题
	public void setTitle(String title) {
		mainView.findViewById(R.id.dialog_title_container).setVisibility(View.VISIBLE);
		TextView msgView = (TextView) mainView.findViewById(R.id.dialog_title);
		msgView.setText(title);
	}

	// 设置确认文案
	public void setPositiveText(String positiveString) {
		TextView msgView = (TextView) mainView.findViewById(R.id.dialog_positive_button);
		msgView.setText(positiveString);
		msgView.setVisibility(View.VISIBLE);
	}

	// 设置取消按钮文案
	public void setNegativeText(String negativeString) {
		TextView msgView = (TextView) mainView.findViewById(R.id.dialog_negative_button);
		msgView.setText(negativeString);
		msgView.setVisibility(View.VISIBLE);
	}
}
